function score = IGDF(Population,optimum)
% <min>
% Inverted generational distance


%% Input:
%                      Dimension                                                   Description
%      obtained_ps     population_size x n_var                                     Obtained Pareto set     
%      reference_ps    num_of_solutions_in_reference_ps x n_var                    Reference Pareto set

%% Output:
%                     Description
%      IGD            Inverted Generational Distance (IGD) of the obtained Pareto set
% PopObj = Population.best.objs;
% obtained_ps = PopObj;
% reference_ps = optimum;
% n_ref=size(reference_ps,1);
% 
% for i=1:n_ref
%     ref_m=repmat(reference_ps(i,:),size(obtained_ps,1),1); 
%     d=obtained_ps-ref_m;    %Calculate the the differences btween the obtained_ps and the reference_ps
%     D=sum(abs(d).^2,2).^0.5;%Calculate the the distance btween the obtained_ps and the reference_ps
%     obtained_to_ref(i)=min(D);
% end
% IGDF=sum(obtained_to_ref)/n_ref;
% score = IGDF;

    PopObj = Population.best.objs;
    if size(PopObj,2) ~= size(optimum,2)
        score = nan;
    else
        score = mean(min(pdist2(optimum,PopObj),[],2));
    end

end